[Dummy] - How different between Pointer and Array from Assembly Perspective ?
Everyone always told that “Pointer could be an Array” and “Array can be considered as a Ponter” so why it need to be divided into two concepts ?
I create a simple program for testing and debugging.
1 | #include <stdio.h> |
Because of its properties, Array can access its element like Pointer, also in reverse with Pointer. It is prove that Pointer can be an Array and Array can be a Pointer.
But the difference is how Asm see it ?
Array
I use Pwndbg for debugging. You can see that how it store my arr and ptr variables in stack :

with the code :
1 | int arr[32] = {0x8, 0x10, 0x18, 0x20}; |
Whenever declare an Array, it store the same way with normal variables, it just combine all the variables with the same type in sequence for easily access. So it will store directly in the stack.

You can see this is how *(arr + 1) work, Asm call directly to the address of arr+1 and assign value for eax, then esi. The computer base on the arr+0 address and calculate to arr+1 address for accessing data, just like a Pointer :>

And you can see it the same way when calling in normal way a[1]

Pointer
ptr stored in rbp-8, storing arr+0 address for accessing data.

The code is plus 1 to ptr for next address variable:
1 | printf("*(ptr+1): %d\n", *(ptr+1)); |
But the Pointer is the opposite with Array, because of knowing entry address of the array, array can access it easily, but the Pointer need to do some calculate for access is adding 0x4 ( size of ptr) like ptr+1 into address value which ptr holding.

and then, ptr can access elements just like array. So you can use ptr for accessing data like array :
1 | printf("ptr[1]: %d\n", ptr[1]); |
Just like that, easily distinguish between Pointer and Array. May be it the same, may be it not..